<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
  //单继承：其实就是把对象的属性一个一个全部复制给新对象
  let extend = function (target,source){
  //  遍历对象中属性
    for(let property in source){
    //  将源对象中的属性复制到目标对象中
      target[property] = source[property];
    }
    return target
  }

//  测试
  let book = {
    name: 'javascript设计模式',
    alike:['css','html']
  }

  let anotherBook = {
    color: 'blue',
  }
  extend(anotherBook,book)
  //属性得到了复制
  console.log(anotherBook,book)
  //修改父类的引用属性
  anotherBook.alike.push('js')
  //子类的引用属性会被影响
  console.log(anotherBook,book)
  //修改父类的基础属性
  anotherBook.name = 'yjm'
  //子类的基础类型属性不会被父类影响
  console.log(anotherBook,book)


//多继承:就是把单继承重复多次
  let mix = function (){
    let i = 1;
    let len = arguments.length
    let target = arguments[0]
    let arg = undefined;
  //  遍历被继承的对象
    for(;i<len;i++){
    //  缓存当前的对象
      arg = arguments[i];
      for(let property in arg){
        target[property] = arg[property];
      }
    }
  }
</script>
</body>
</html>
